package com.android.job.service.request;

import java.util.ArrayList;

import org.apache.http.message.BasicNameValuePair;

import android.os.Handler;
import android.util.Log;

import com.android.job.fusion.FusionCode;
import com.android.job.service.ConnectionTask;
import com.android.job.service.JSONRequest;
import com.android.job.util.CommonUtil;
import com.android.job.util.json.JSONException;
import com.android.job.util.json.JSONObject;

public class InterviewRequest extends JSONRequest
{
	private String companyId;
	private String personnelId;
	private String postId;
	

	public InterviewRequest(Handler handler, String httpUrl)
	{
		super(handler, httpUrl);
		setHttpType(ConnectionTask.POST);
	}

	public void setValues(String companyId, String personnelId ,String postId)
	{
		this.companyId = companyId;
		this.personnelId = personnelId;
		this.postId = postId;
	}

	@Override
	protected boolean parseJSONResponse(JSONObject json)
	{
		Log.i("InterviewRequest", "====response======json======"+json.toString());
		if (!json.isNull("jsonData"))
		{
			JSONObject jsonObject;
			try
			{
				jsonObject = json.getJSONObject("jsonData");

				if (!jsonObject.isNull("success"))
				{
					String success = jsonObject.getString("success");
					CommonUtil.sendMessage(handler, FusionCode.RETURN_JSONOBJECT,
							success);
				}
			}
			catch (JSONException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}

		return true;
	}

	@Override
	protected void appendMainBody()
	{
		this.paramsters = new ArrayList();
		JSONObject userJson;
		try
		{
			jsonObject = new JSONObject();
			userJson = new JSONObject();

			userJson.put("companyId", companyId);
			userJson.put("personnelId", personnelId);
			userJson.put("postId", postId);
			jsonObject.put("requestType", "interview");
			jsonObject.put("jsonData", userJson);
			paramsters.add(new BasicNameValuePair("jsonData", jsonObject.toString()));
			Log.i("InterviewRequest","===request===json======"+jsonObject.toString());
		} catch (JSONException e)
		{
			e.printStackTrace();
		}
	}

}
